MOD = 10 ** 9 + 7


class Solution:
    def minNonZeroProduct(self, p: int) -> int:
        v1 = pow(2, p) - 1
        v2 = pow(2, p) - 2
        num = pow(2, p - 1) - 1
        return (pow(v2, num, mod=MOD) * v1) % MOD


if __name__ == "__main__":
    print(Solution().minNonZeroProduct(1))  # 1
    print(Solution().minNonZeroProduct(2))  # 6
    print(Solution().minNonZeroProduct(3))  # 1512
    print(Solution().minNonZeroProduct(31))  # 138191773
